import React,{useEffect,useState} from 'react'

export default function EffectDemo() {
    const [count,setCount]=useState(0)
    const [age,setAge]=useState(18)
    useEffect(()=>{
      console.log('===useEffect被执行====');
      let timers=setInterval(() => {
            console.log('-------------------');
            setCount(count+1)
      }, 1000);
      return ()=>{
         console.log('模拟销毁功能');
         clearInterval(timers)
      }
    },[])
    return (
      <div>
          <div>
              {count}
              <button onClick={()=>{setCount(count+1)}}>+</button>
          </div>
          <div>
            {age} <button onClick={()=>setAge(age+1)}>增加年龄</button>
          </div>
      </div>
    )
}
